package com.bawei.model_sevent.Activity.Fragemnt;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.widget.ViewPager2;

import com.bawei.model_sevent.Activity.Adapter.FragmentAdapter_class;
import com.bawei.model_sevent.R;

import java.util.ArrayList;

import q.rorbin.verticaltablayout.VerticalTabLayout;
import q.rorbin.verticaltablayout.adapter.TabAdapter;
import q.rorbin.verticaltablayout.widget.ITabView;
import q.rorbin.verticaltablayout.widget.TabView;

public class BlankFragment_class extends Fragment {
    private VerticalTabLayout tabClass;
    private ViewPager2 vgClass;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_blank_class, container, false);
        tabClass = inflate.findViewById(R.id.tab_class);
        vgClass = inflate.findViewById(R.id.vg_class);
        ArrayList<String> strings = new ArrayList<>();
        strings.add("电脑办公");
        strings.add("手机数码");
        strings.add("男装");
        strings.add("女装");
        strings.add("家电用器");
        strings.add("食用生鲜");
        strings.add("酒水饮料");
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new BlankFragment1());
        fragments.add(new BlankFragment2());
        fragments.add(new BlankFragment3());
        fragments.add(new BlankFragment4());
        fragments.add(new BlankFragment5());
        FragmentAdapter_class fragmentAdapter_class = new FragmentAdapter_class(getActivity().getSupportFragmentManager(), getActivity().getLifecycle(),fragments);
        vgClass.setAdapter(fragmentAdapter_class);
        tabClass.addOnTabSelectedListener(new VerticalTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabView tab, int position) {
                switch (position)
                {
                    case 0:
                        vgClass.setCurrentItem(0,false);
                        break;
                    case 1:
                        vgClass.setCurrentItem(1,false);
                        break;
                    case 2:
                        vgClass.setCurrentItem(2,false);
                        break;
                    case 3:
                        vgClass.setCurrentItem(3,false);
                        break;
                    case 4:
                        vgClass.setCurrentItem(4,false);
                        break;
                }
            }

            @Override
            public void onTabReselected(TabView tab, int position) {

            }
        });
        tabClass.setTabAdapter(new TabAdapter() {
            @Override
            public int getCount() {
                return strings.size();
            }

            @Override
            public ITabView.TabBadge getBadge(int position) {
                return null;
            }

            @Override
            public ITabView.TabIcon getIcon(int position) {
                return null;
            }

            @Override
            public ITabView.TabTitle getTitle(int position) {
                return new ITabView.TabTitle.Builder()
                        .setContent(strings.get(position))
                        .setTextColor(Color.BLUE,Color.BLACK)
                        .build();
            }

            @Override
            public int getBackground(int position) {
                return 0;
            }
        });
        tabClass.setIndicatorColor(Color.BLUE);
        return inflate;
    }
}